<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教育程度" prop="education">
        <el-input
          v-model="queryParams.education"
          placeholder="请输入教育程度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信" prop="weChat">
        <el-input
          v-model="queryParams.weChat"
          placeholder="请输入微信"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向院校" prop="intentionCollege">
        <el-input
          v-model="queryParams.intentionCollege"
          placeholder="请输入意向院校"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向专业" prop="intentionProfessional">
        <el-input
          v-model="queryParams.intentionProfessional"
          placeholder="请输入意向专业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:information:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:information:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:information:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="手机号码" align="center" prop="phone" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="教育程度" align="center" prop="education" />
      <el-table-column label="户口性质" align="center" prop="householdRegister" />
      <el-table-column label="报考地区" align="center" prop="province" />
      <el-table-column label="毕业证邮寄地址" align="center" prop="address" />
      <el-table-column label="微信" align="center" prop="weChat" />
      <el-table-column label="报考院校" align="center" prop="intentionCollege" />
      <el-table-column label="报考专业" align="center" prop="intentionProfessional" />
<!--      <el-table-column label="身份证正面" align="center" prop="idCardPositive" >-->
<!--        <template slot-scope="scope">-->
<!--          <img :src="scope.row.idCardPositive" alt=""/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="身份证反面" align="center" prop="idCardNegative">-->
<!--        <template slot-scope="scope">-->
<!--          <img :src="scope.row.idCardNegative" alt=""/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="毕业照" align="center" prop="graduationPhoto" />-->
<!--      <el-table-column label="电子照片" align="center" prop="electronicPhotos" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="check(scope.row)"
            v-hasPermi="['system:information:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:information:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:information:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="详细信息" :visible.sync="viewVisible" append-to-body>
      <el-descriptions title="">
      <el-descriptions-item label="姓名">{{ view.name }}</el-descriptions-item>
      <el-descriptions-item label="手机号码">{{ view.phone }}</el-descriptions-item>
      <el-descriptions-item label="身份证号">{{ view.idCard }}</el-descriptions-item>
      <el-descriptions-item label="教育程度">{{ view.education }}</el-descriptions-item>
      <el-descriptions-item label="微信">{{ view.weChat }}</el-descriptions-item>
      <el-descriptions-item label="意向院校">{{ view.intentionCollege }}</el-descriptions-item>
      <el-descriptions-item label="意向专业">{{ view.intentionProfessional }}</el-descriptions-item>
      <el-descriptions-item label="身份证正面照">
        <el-image
          style="width: 100px; height: 100px"
          :src="baseUrl + view.idCardPositive"
          fit="fill"
          :preview-src-list="srcList"
        >
        </el-image>
      </el-descriptions-item>
        <el-descriptions-item label="身份证反面">
          <el-image
            style="width: 100px; height: 100px"
            :src="baseUrl + view.idCardNegative"
            fit="fill"
            :preview-src-list="srcList"
          >
          </el-image>
        </el-descriptions-item>
        <el-descriptions-item label="毕业照">
          <el-image
            style="width: 100px; height: 100px"
            :src="baseUrl + view.graduationPhoto"
            fit="fill"
            :preview-src-list="srcList">
          </el-image>
        </el-descriptions-item>
        <el-descriptions-item label="电子照片">
          <el-image v-for="item in electronicPhotoList"
            style="width: 100px; height: 100px"
            :src="baseUrl + item"
            fit="fill"
            :preview-src-list="srcList"
          >
          </el-image>
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
    <!-- 添加或修改报名学生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="教育程度" prop="education">
          <el-input v-model="form.education" placeholder="请输入教育程度" />
        </el-form-item>
        <el-form-item label="省份" prop="province">
          <el-input v-model="form.province" placeholder="请输入省份" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="微信" prop="weChat">
          <el-input v-model="form.weChat" placeholder="请输入微信" />
        </el-form-item>
        <el-form-item label="意向院校" prop="intentionCollege">
          <el-input v-model="form.intentionCollege" placeholder="请输入意向院校" />
        </el-form-item>
        <el-form-item label="意向专业" prop="intentionProfessional">
          <el-input v-model="form.intentionProfessional" placeholder="请输入意向专业" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInformation, getInformation, delInformation, addInformation, updateInformation, exportInformation } from "@/api/system/information";

export default {
  name: "Information",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报名学生信息表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        phone: null,
        email: null,
        idCard: null,
        education: null,
        province: null,
        address: null,
        weChat: null,
        intentionCollege: null,
        intentionProfessional: null,
        idCardPositive: null,
        idCardNegative: null,
        graduationPhoto: null,
        electronicPhotos: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      viewVisible: false,
      view: {},
      baseUrl: process.env.VUE_APP_BASE_API,
      srcList: [],
      electronicPhotoList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报名学生信息列表 */
    getList() {
      this.loading = true;
      listInformation(this.queryParams).then(response => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        phone: null,
        email: null,
        idCard: null,
        education: null,
        province: null,
        address: null,
        weChat: null,
        intentionCollege: null,
        intentionProfessional: null,
        idCardPositive: null,
        idCardNegative: null,
        graduationPhoto: null,
        electronicPhotos: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报名学生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInformation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报名学生信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除报名学生信息编号为"' + ids + '"的数据项？').then(function() {
        return delInformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有报名学生信息数据项？').then(() => {
        this.exportLoading = true;
        return exportInformation(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    },
    check(row){
      this.view = row
      this.srcList = []
      this.electronicPhotoList = []
      this.srcList.push(this.baseUrl + this.view.graduationPhoto)
      this.srcList.push(this.baseUrl + this.view.idCardNegative)
      this.srcList.push(this.baseUrl + this.view.idCardPositive)
      if(row.electronicPhotos){
        let srcs = row.electronicPhotos.split(',')
        for (let src of srcs) {
          debugger
          this.srcList.push(this.baseUrl + src)
          this.electronicPhotoList.push(src)
        }
      }
      this.viewVisible = true
      console.log('其他电子照片',this.electronicPhotoList)
      console.log(this.srcList)
      console.log(this.view.graduationPhoto)
    }
  }
};
</script>
